<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>天天生鲜-用户中心</title>
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <script type="text/javascript" src="js/jquery-1.12.4.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="js/slide.js"></script>
</head>
<body>
<script>
    $(document).ready(function(){
        $.ajax({
            url:"GetUserAddress",
            data:{user_id:${Session.loginuser.user_id}},
            dataType:"json",
            type:"GET",
            success:function (msg){
                var defaultAddress=msg.defaultAddress;
                var addressList=msg.addressList;
                //alert(addressList);
                var str="";
                var str1="";
                if(addressList!=null && addressList.length>0){
                    for(var i=0;i<addressList.length;i++){
                    str = str +'<div class="site_con">'+
                        '<dl>' +
                        '<dt>地址'+(i+1)+'：</dt>' +
                        '<dd>'+addressList[i].address_name+' 收 '+addressList[i].address_phone+'</dd>' +
                        '<dd>'+addressList[i].address+'</dd>'+
                        '<dd><button class="info_submit" onclick="" data-toggle="modal" data-target="#myModal">编辑 </button> '+
                        '<button class="info_submit" onclick="deleteAddress('+addressList[i].address_id+')">删除地址</button></dd>'+
                        '</dl>' +
                        '</div>'
                    }
                }else{
                    str = str +'<div class="site_con">' +
                        '<dl>' +
                        '<dt>地址：</dt>' +
                        '<dd>尚未添加地址</dd>' +
                        '<dd><button onclick="">添加地址</button></dd>'+
                        '</dl>' +
                        '</div>'
                }
                $("#DefaultAddress").html(str);


            }
        })
    })
</script>
<script>
    function deleteAddress(address_id){
        if(confirm("是否确认删除该地址！")){
            location.href="deleteAddress?address_id="+address_id;
        }

    }
</script>

<script>
    //验证添加地址填写的内容
    function checkall(){
        if(check1() == true && check2() == true && check3() == true){
            return true;
        }
        return false;
    }

    function check1(t){
        /*手机号*/
        var mobile=$("#address_phone");

        //含有非法字符
        /*var emai=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
        var phon=/^1[3|4|5|8][0-9]\d{4,8}$/;
        if(!emai.test(this.value)||!phon.test(this.value))*//*这样不可以*/
        var pho=/^1[3|4|5|8][0-9]\d{4,8}$/;
        if(t.value==""){
            $('#a_phone').html('<i>手机号不能为空</i>');
            mobile.val("");
        }else if(!pho.test(t.value)){
            $('#a_phone').html('<i></i>手机号格式不正确。');
            mobile.val("");
           return false;
        }else{
            return true;
        }
    }

    function check2(t){
        /*收件人*/
        var user_name=$("#address_name");
        if(t.value=="") {
            $('#a_name').html('<i></i>密码不能为空。');
            user_name.val("");
            return false;
        }else{
            return true;
        }
    }

    function check3(t){
        /*收件地址*/
        var user_address=$("#address");
        if(t.value=="") {
            $('#a_address').html('<i class="fail_fa"></i>地址不能为空。');
            user_address.val("");
            return false;
        }else{
            return true;
        }
    }
</script>

<script>

</script>

<script type="text/javascript">
    // $(function () {
    //     $("#edit_modal").click(function () {
    //         $("#Mymodal").modal({
    //             backdrop: false, // 相当于data-backdrop
    //             keyboard: false, // 相当于data-keyboard
    //             show: true // 相当于data-show
    //         });
    //     });
    // });
    // 点击显示弹窗
     function edit_modal(Address){
        $("#edit_modal").click(function(){
            $("#Mymodal").modal({
                backdrop: false, // 相当于data-backdrop
                keyboard: false, // 相当于data-keyboard
                show: true, // 相当于data-show
            });
        })
        var str2='';
        str2=str2+' <form action="editAddress">' +
            '<input type="hidden" value="'+Address.address_id+'" id="address_id" name="address_id">'+
            '<div class="form_group">' +
            ' &nbsp;&nbsp;<label>收件人：</label>&nbsp;' +
            '  <input type="text" value="'+Address.address_name+'" id="address_name" name="address_name" onblur="check2(this)"><span id="a_name"></span>' +
            '</div>' +
            '<div class="form_group">' +
            '  &nbsp;&nbsp;&nbsp;&nbsp;<label>手机：</label>' +
            '  <input type="text" value="'+Address.address_phone+'" id="address_phone" name="address_phone" onblur="check1(this)"><sapn id="a_phone"></sapn>' +
            '</div>' +
            '<div class="form_group form_group2">' +
            '  &nbsp;&nbsp;<label>详细地址：</label>' +
            '  <textarea class="site_area" value="'+Address.address+'" id="address" name="address" onblur="check3()"></textarea><span id="a_address"></span>' +
            '</div>' +
            '<input type="submit" value="提交" class="info_submit">' +
            '</form>';
        $("#modal-body").html(str2);
    }

</script>

<div class="header_con">
    <div class="header">
        <div class="welcome fl">欢迎来到天天生鲜!</div>
        <div class="fr">
            <div class="login_info fl">
                欢迎您：<em>张 山</em>
            </div>
            <div class="login_btn fl">
                <a href="login">登录</a>
                <span>|</span>
                <a href="register">注册</a>
            </div>
            <div class="user_link fl">
                <span>|</span>
                <a href="user_center_info">用户中心</a>
                <span>|</span>
                <a href="cart">我的购物车</a>
                <span>|</span>
                <a href="user_center_order">我的订单</a>
            </div>
        </div>
    </div>
</div>

<div class="search_bar clearfix">
    <a href="index" class="logo fl"><img src="images/logo.png"></a>
    <div class="sub_page_name fl">|&nbsp;&nbsp;&nbsp;&nbsp;用户中心</div>
    <div class="search_con fr">
        <input type="text" class="input_text fl" name="" placeholder="搜索商品">
        <input type="button" class="input_btn fr" name="" value="搜索">
    </div>
</div>

<div class="main_con clearfix">
    <div class="left_menu_con clearfix">
        <h3>用户中心</h3>
        <ul>
            <li><a href="user_center_info">· 个人信息</a></li>
            <li><a href="user_center_order">· 全部订单</a></li>
            <li><a href="user_center_sitel" class="active">· 收货地址</a></li>
        </ul>
    </div>
    <div class="right_content clearfix">
        <h3 class="common_title2">收货地址 &nbsp;&nbsp;<a href="#addAddress">添加地址</a></h3>
        <div class="site_con" id="DefaultAddress">
            <#--<dl>-->
                <#--<dt>当前地址：</dt>-->
                <#--<dd>北京市 海淀区 东北旺西路8号中关村软件园 （李思 收） 182****7528</dd>-->
            <#--</dl>-->
        </div>
        <div id="addAddress" >
        <h3 class="common_title2">添加地址</h3>
        <div class="site_con">
            <form action="addAddress">
                <div class="form_group">
                    <label>收件人：</label>
                    <input type="text" value="" id="address_name" name="address_name" onblur="check2(this)"><span id="a_name"></span>
                </div>
                <div class="form_group">
                    <label>手机：</label>
                    <input type="text" value="" id="address_phone" name="address_phone" onblur="check1(this)"><sapn id="a_phone"></sapn>
                </div>
                <div class="form_group form_group2">
                    <label>详细地址：</label>
                    <textarea class="site_area" value="" id="address" name="address" onblur="check3()"></textarea><span id="a_address"></span>
                </div>
                <input type="submit" value="提交" class="info_submit">
            </form>
        </div>
        </div>

    </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">编辑地址</h4>
            </div>
            <form action="editAddress">
                <div class="form_group">
                    <label>收件人：</label>
                    <input type="text" value="" id="address_name" name="address_name" onblur="check2(this)"><span id="a_name"></span>
                </div>
                <div class="form_group">
                    <label>手机：</label>
                    <input type="text" value="" id="address_phone" name="address_phone" onblur="check1(this)"><sapn id="a_phone"></sapn>
                </div>
                <div class="form_group form_group2">
                    <label>详细地址：</label>
                    <textarea class="site_area" value="" id="address" name="address" onblur="check3()"></textarea><span id="a_address"></span>
                </div>
                <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="submit" class="btn btn-primary">保存</button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<div class="footer">
    <div class="foot_link">
        <a href="#">关于我们</a>
        <span>|</span>
        <a href="#">联系我们</a>
        <span>|</span>
        <a href="#">招聘人才</a>
        <span>|</span>
        <a href="#">友情链接</a>
    </div>
    <p>CopyRight © 2016 北京天天生鲜信息技术有限公司 All Rights Reserved</p>
    <p>电话：010-****888    京ICP备*******8号</p>
</div>

</body>
</html>